package com.atguigu.udmp.web.userprofile.scheduler;


import com.atguigu.udmp.web.userprofile.bean.TaskInfo;
import com.atguigu.udmp.web.userprofile.constant.ConstCodes;
import com.atguigu.udmp.web.userprofile.service.TaskExecuteService;
import com.atguigu.udmp.web.userprofile.service.TaskInfoService;
import org.apache.commons.lang3.time.DateFormatUtils;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.scheduling.annotation.Scheduled;
import org.springframework.stereotype.Component;

import java.text.DateFormat;
import java.util.Date;
import java.util.List;

@Component
public class TaskScheduler {

    @Autowired
    TaskInfoService taskInfoService;

    @Autowired
    TaskExecuteService taskExecuteService;

    @Scheduled(cron = "0 0/10 * * * *")//  10分钟级
    public void testSchedule10m(){

        taskExecuteService.exec(ConstCodes.TASK_EXEC_CYCLE_10M, DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
    }

    @Scheduled(cron = "0 * * * * *")//  1分钟级
    public void testSchedule1M(){

        taskExecuteService.exec(ConstCodes.TASK_EXEC_CYCLE_1M, DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
    }

    @Scheduled(cron = "0 0 * * * *")//  1 小时级
    public void testSchedule1H(){

        taskExecuteService.exec(ConstCodes.TASK_EXEC_CYCLE_1H, DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
    }

    @Scheduled(cron = "0 0 2 * * *")//  1天
    public void testSchedule1D(){

        taskExecuteService.exec(ConstCodes.TASK_EXEC_CYCLE_1D, DateFormatUtils.format(new Date(),"yyyy-MM-dd"));
    }

}
